-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang][bytecode] Implement __builtin_f{maximum,minimum}_num #112335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesFull diff: https://github.com/llvm/llvm-project/pull/112335.diff 3 Files Affected:
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index ec27aebf84bd80..65c7b4e5306d72 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -333,39 +333,48 @@ static bool interp__builtin_copysign(InterpState &S, CodePtr OpPC,
}
static bool interp__builtin_fmin(InterpState &S, CodePtr OpPC,
- const InterpFrame *Frame, const Function *F) {
+ const InterpFrame *Frame, const Function *F,
+ bool IsNumBuiltin) {
const Floating &LHS = getParam<Floating>(Frame, 0);
const Floating &RHS = getParam<Floating>(Frame, 1);
Floating Result;
- // When comparing zeroes, return -0.0 if one of the zeroes is negative.
- if (LHS.isZero() && RHS.isZero() && RHS.isNegative())
- Result = RHS;
- else if (LHS.isNan() || RHS < LHS)
- Result = RHS;
- else
- Result = LHS;
+ if (IsNumBuiltin) {
+ Result = llvm::minimumnum(LHS.getAPFloat(), RHS.getAPFloat());
+ } else {
+ // When comparing zeroes, return -0.0 if one of the zeroes is negative.
+ if (LHS.isZero() && RHS.isZero() && RHS.isNegative())
+ Result = RHS;
+ else if (LHS.isNan() || RHS < LHS)
+ Result = RHS;
+ else
+ Result = LHS;
+ }
S.Stk.push<Floating>(Result);
return true;
}
static bool interp__builtin_fmax(InterpState &S, CodePtr OpPC,
- const InterpFrame *Frame,
- const Function *Func) {
+ const InterpFrame *Frame, const Function *Func,
+ bool IsNumBuiltin) {
const Floating &LHS = getParam<Floating>(Frame, 0);
const Floating &RHS = getParam<Floating>(Frame, 1);
Floating Result;
- // When comparing zeroes, return +0.0 if one of the zeroes is positive.
- if (LHS.isZero() && RHS.isZero() && LHS.isNegative())
- Result = RHS;
- else if (LHS.isNan() || RHS > LHS)
- Result = RHS;
- else
- Result = LHS;
+ if (IsNumBuiltin) {
+ Result = llvm::maximumnum(LHS.getAPFloat(), RHS.getAPFloat());
+ } else {
+ // When comparing zeroes, return +0.0 if one of the zeroes is positive.
+ if (LHS.isZero() && RHS.isZero() && LHS.isNegative())
+ Result = RHS;
+ else if (LHS.isNan() || RHS > LHS)
+ Result = RHS;
+ else
+ Result = LHS;
+ }
S.Stk.push<Floating>(Result);
return true;
@@ -1701,7 +1710,16 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
case Builtin::BI__builtin_fminl:
case Builtin::BI__builtin_fminf16:
case Builtin::BI__builtin_fminf128:
- if (!interp__builtin_fmin(S, OpPC, Frame, F))
+ if (!interp__builtin_fmin(S, OpPC, Frame, F, /*IsNumBuiltin=*/false))
+ return false;
+ break;
+
+ case Builtin::BI__builtin_fminimum_num:
+ case Builtin::BI__builtin_fminimum_numf:
+ case Builtin::BI__builtin_fminimum_numl:
+ case Builtin::BI__builtin_fminimum_numf16:
+ case Builtin::BI__builtin_fminimum_numf128:
+ if (!interp__builtin_fmin(S, OpPC, Frame, F, /*IsNumBuiltin=*/true))
return false;
break;
@@ -1710,7 +1728,16 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
case Builtin::BI__builtin_fmaxl:
case Builtin::BI__builtin_fmaxf16:
case Builtin::BI__builtin_fmaxf128:
- if (!interp__builtin_fmax(S, OpPC, Frame, F))
+ if (!interp__builtin_fmax(S, OpPC, Frame, F, /*IsNumBuiltin=*/false))
+ return false;
+ break;
+
+ case Builtin::BI__builtin_fmaximum_num:
+ case Builtin::BI__builtin_fmaximum_numf:
+ case Builtin::BI__builtin_fmaximum_numl:
+ case Builtin::BI__builtin_fmaximum_numf16:
+ case Builtin::BI__builtin_fmaximum_numf128:
+ if (!interp__builtin_fmax(S, OpPC, Frame, F, /*IsNumBuiltin=*/true))
return false;
break;
diff --git a/clang/test/Sema/constant-builtins-fmaximum-num.cpp b/clang/test/Sema/constant-builtins-fmaximum-num.cpp
index 206be5d407654c..32d415ca9ee984 100644
--- a/clang/test/Sema/constant-builtins-fmaximum-num.cpp
+++ b/clang/test/Sema/constant-builtins-fmaximum-num.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
-// FIXME: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
// expected-no-diagnostics
constexpr double NaN = __builtin_nan("");
diff --git a/clang/test/Sema/constant-builtins-fminimum-num.cpp b/clang/test/Sema/constant-builtins-fminimum-num.cpp
index 7ec7427dba72b9..d54f1ec84ad6fc 100644
--- a/clang/test/Sema/constant-builtins-fminimum-num.cpp
+++ b/clang/test/Sema/constant-builtins-fminimum-num.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
-// FIXME: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
// expected-no-diagnostics
constexpr double NaN = __builtin_nan("");
|
Collaborator
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/7076 Here is the relevant piece of the build log for the reference |
DanielCChen
pushed a commit
to DanielCChen/llvm-project
that referenced
this pull request
Oct 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.